package com.syni.mdd.yhd.common.all.controller.protect;

/**
 * @className BmsBusinessController
 * @description TOO
 * @Author cfx
 * @DATE 2019/4/15 14:25
 * @VERSION 1.0
 **/

import com.syni.mdd.sjb.common.component.utils.common.annotations.CheckParams;
import com.syni.mdd.yhd.common.all.constants.Constants;
import com.syni.mdd.yhd.common.all.constants.ResultCode;
import com.syni.mdd.yhd.common.all.service.BmsCommonService;
import com.syni.mdd.yhd.common.all.service.BmsUserComplainService;
import com.syni.mdd.sjb.common.component.utils.common.utils.ResultMapHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/userComplain")
public class BmsUserComplainController {
    @Autowired
    BmsUserComplainService bmsUserComplainService;

    @PostMapping("/complainCommit")
    @CheckParams(checkAuth = true,params = {"video_id","complain_type"})
    public Map<String,Object> complainCommit(@RequestBody Map<String,Object> paramsMap){
        String userIdentify = paramsMap.get("userIdentify").toString();
        Integer client = Integer.parseInt(paramsMap.get("client").toString());
        Integer videoId = Integer.parseInt(paramsMap.get("video_id").toString());
        Integer complainType = Integer.parseInt(paramsMap.get("complain_type").toString());
        Integer createWay = BmsCommonService.clientMap.get(client);
        String content = "";
        if(paramsMap.containsKey("content") && !"".equals(paramsMap.get("content").toString())){
            content = paramsMap.get("content").toString();
            if(content.length() > Constants.MAX_CONTENT_LENG){
                return ResultMapHelper.result(ResultCode.CODE_BUSINESS_REPORT_ERROR_LONG,"内容过长");
            }
        }
        return bmsUserComplainService.complain(Integer.parseInt(userIdentify),videoId,
                complainType,content,createWay);
    }

}
